package movieGandalf.dataObjects;

import java.sql.Connection;

import movieGandalf.database.MovieTools;
import movieGandalf.logicGuiConnection.Country;

public class CountryImp implements Country{
	
	private Integer id;
	
	private String country;
	
	public CountryImp(Integer id, String country){
		this.id = id;
		this.country = country;
	}
	
	public Integer getID() {
		return this.id;
	}
	
	public String getCountry() {
		if (country != null)
			return country;
		
		if (id == null)
			return null;
		
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		country = MovieTools.getCountry(conn, this.id);
		
		return country;
	}

	public void setID(Integer newID) {
		this.id = newID;
		
	}
	
	public void setCountry(String newCountry) {
		this.country = newCountry;
	}

	public boolean update() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.updateCountry(conn, this);
	}
	
	public boolean delete() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteObject(conn,this);
	}
}
